package com.example.demo.concurrent.interrupt;

import lombok.extern.slf4j.Slf4j;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-06-28
 * Time: 12:01
 */
@Slf4j(topic = "c.InterruptTest4")
public class InterruptTest4 {
    public static void main(String[] args) throws InterruptedException {
        //1.打断正在运行的线程
        Thread t1 = new Thread(() -> {
            while(true) {
                log.debug("sleep");
                boolean interrupted = Thread.currentThread().isInterrupted();
                if(interrupted) {
                    //由被打断线程自己去决定,是继续运行还是停止
                   break;
                }
            }
        }, "t1");
        Thread.yield();
        t1.start();
        t1.interrupt();
    }
}
